package com.fowo.api.service.handleWork;

import com.fowo.api.entity.PurchaseRgoodsOrder;
import com.fowo.api.model.purchase.rgoods.order.PurchaseRgoodsOrderWasteAction;
import com.fowo.api.service.impl.PurchaseRgoodsOrderServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

@Component
public class purchaseRgoodsOrderWasteAction implements PurchaseRgoodsOrderWasteAction {

    @Resource
    private PurchaseRgoodsOrderServiceImpl purchaseRgoodsOrderService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void run(List<Long> idList) throws Exception {
        for(int i=0;i<idList.size();i++){
            PurchaseRgoodsOrder byId = purchaseRgoodsOrderService.getById(idList.get(i));
            handle(byId);
        }
    }
    void handle(PurchaseRgoodsOrder byId){
        Assert.isTrue(!byId.getStatus().equals("3"),"违规操作");
        byId.setStatus("2");
        purchaseRgoodsOrderService.updateById(byId);
    }
}
